package cn.chengpengper.rpc.common.threadpool;

import java.util.concurrent.*;

/**
 * @author chengpeng.hu
 */
public class ServerThreadPool {

    private static ThreadPoolExecutor threadPoolExecutor;

    static {
        ThreadFactory threadFactory =
                new ThreadFactory() {
                    final ThreadFactory defaultFactory = Executors.defaultThreadFactory();

                    @Override
                    public Thread newThread(final Runnable r) {
                        Thread thread = defaultFactory.newThread(r);
                        thread.setName("ProviderWorker-" + thread.getName());
                        return thread;
                    }
                };
        threadPoolExecutor = new ThreadPoolExecutor(16, 16, 600L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(65536), threadFactory);
    }

    public static void submit(Runnable task) {
        threadPoolExecutor.submit(task);
    }

    public static void shutdown() {
        threadPoolExecutor.shutdown();
    }
}
